package com.atguigu.chapter05

object TestFunction4 {

  def main(args: Array[String]): Unit = {

    def operation(arr: Array[Int], op: Int => Int) = {
      for (elem <- arr) yield op(elem)
    }

    def op(ele: Int): Int = {
      ele + 1
    }

    val arr = operation(Array(1, 2, 3, 5), op)
    println(arr.mkString(","))

    val arr1 = operation(Array(1,2,3,5),(ele: Int)=>{
      ele + 1
    })

    println(arr1.mkString(","))

    val arr2 = operation(Array(1,2,3,45,5),(ele)=>{
      ele+1
    })

    println(arr2.mkString(","))

    val arr3 = operation(Array(1,2,3,45,5),ele=>{
      ele+2
    })

    println(arr3.mkString(","))

    val arr5 = operation(Array(1, 2, 3, 45, 5), _ + 1)

    println(arr5.mkString(","))

  }
}
